/***
 *	签到 
 */
function setSign(){
	art.dialog.open(
		ctx + "/setSign.html?actionType=1", 
		{
			title: "签到",
			width:"450px", 
			height:"300px", 
			button:[
		        {
		        	name: "保存签到",
		            callback: function () {
		        		if(isUndefined(saveNotepad())){
			        		$("button").attr("disabled", true);
		        			this.close();
		        		}	
		                return false;
		            },
		            focus: true
		        },
		        {
		        	name: "取消"
		        }
			],
			lock: true
		}
	);
}

/***
 *	记事 
 */
function setNote(){
	art.dialog.open(
			ctx + "/setNote.html?actionType=2", 
			{
				title: "记事",
				width:"450px", 
				height:"150px", 
				button:[
			        {
			        	name: "保存记事",
			            callback: function () {
			        		if(isUndefined(saveNotepad())){
				        		$("button").attr("disabled", true);
			        			this.close();
			        		}	
			                return false;
			            },
			            focus: true
			        },
			        {
			        	name: "取消"
			        }
				],
				lock: true
			}
		);
}

/***
 * 保存签到、记事信息
 * @return
 */
function saveNotepad(){
	//1.获取参数
	var actionType = $(window.frames[0].document).find("#actionType").val();
	var period = $(window.frames[0].document).find("#period").val();
	var type = window.frames[0].$("input[name='notepad.type']:checked").val();
	var content = $.trim($(window.frames[0].document).find("#content"+period).val());
	
	//2.验证参数
	if (isUndefined(type) || type == null || "" == type) {
		art.dialog.tips("<label class='warn'>请选择一个事项！</label>", 1.5);
		return false;
	}
	if(actionType == 2){
		if (isUndefined(content) || content == null || "" == content) {
			art.dialog.tips("<label class='warn'>您好像忘了输一些内容！</label>", 1.5);
			return false;
		}		
	}
	
	//3.发送请求
	var url = ctx + "/saveNotepad.html?ajax=true";
	var param = "&actionType=" + actionType + "&period=" + period + "&type=" + type + "&content=" + encodeURIComponent(content);
	var sf = function (msg) {
		if (msg == 1 || msg == "1" || msg == "\"1\"") {
			art.dialog.tips("<label class='success'>保存成功！</label>", 2);
			window.location.href = ctx + "/userCenter.html";
		}else{
			art.dialog.tips("<label class='error'>保存失败，请刷新页面重试！</label>", 1.5);
		}
	};
	ajax(url, param, sf);
}

/***
 * 查询签到、记事信息
 * @return
 */
function searchNotepad(id, name, currentPage, pageSize, themeType){	
	var flag = false;
	var url = ctx + "/searchNotepad.html?ajax=true";
	var param = "&actionType=" + id;
	if(!isUndefined(currentPage) && !isUndefined(pageSize)){
		param += "&currentPage=" + currentPage + "&pageSize=" + pageSize;
	}
	if (!isUndefined(themeType) && themeType != null && "" != themeType) {
		param += "&themeType=" + themeType;
		flag = true;
	}
	var sf = function (msg) {
		if (msg != null || msg != "") {
			$("#" + name).html(msg);
			if(flag){
	            $('#pageBar_' + name).smartpaginator({ 
	                totalrecords: $('#total_' + name).val(), 
	                recordsperpage: 10, 
	                length: $('#len_' + name).val(), 
	                next: '下一页', 
	                prev: '上一页', 
	                first: '首页', 
	                last: '尾页', 
	                theme: 'blue', 
	                controlsalways: true, 
	                onchange: function (newPage) {
	                	searchNotepad(id, name, newPage, 10, 2);
	           		}
	           	});	
			}
		}else{
			$("#" + name).html("暂无内容，快去添加新的记事或签到！");
		}
	};
	ajax(url, param, sf);	
}
